﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Taobao.Top.Api.Domain;
using Taobao.Top.Api.Request;
using Taobao.Top.Api;
using TopHelper;
using System.Text;
public partial class index : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["top_session"] != null)
            {
                Session["sessionKey"] = Request.QueryString["top_session"];
                Session["pageCount"] = Common.GetRateCount(Session["sessionKey"].ToString());
            }
            else
            {
                Response.Redirect("http://container.open.taobao.com/container?appkey=12112146", false);
            }
            if (Request.QueryString["top_parameters"]!=null)
            {
                GetUserName(Request.QueryString["top_parameters"].ToString());
            }
            if (Session["pageCount"] == null)
            {
                Session["pageCount"] = 0;
            }
        }
    }
    protected void GetUserName(string topParameters)
    {
        byte[] outputb = Convert.FromBase64String(topParameters);
        string orgStr = Encoding.Default.GetString(outputb);
        string[] parameters = orgStr.Split('&');
        Dictionary<string, string> dict = new Dictionary<string, string>();
        foreach (string parameter in parameters)
        {
            string[] key = parameter.Split('=');
            dict.Add(key[0], key[1]);
        }
        Session["userName"] = dict["visitor_nick"];
        return;
    }
}